package com.ktjy.ktmall.controller.vo;

import com.ktjy.common.annotation.Log;
import com.ktjy.common.core.controller.BaseController;
import com.ktjy.common.core.domain.AjaxResult;
import com.ktjy.common.core.page.TableDataInfo;
import com.ktjy.common.enums.BusinessType;
import com.ktjy.common.utils.poi.ExcelUtil;
import com.ktjy.ktmall.domain.dto.SkuAttrValues;
import com.ktjy.ktmall.service.dto.ISkuAttrValuesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * sku属性值表Controller
 *
 * @author ktjy
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/ktmall/skuesvalues")
public class SkuAttrValuesController extends BaseController
{
    @Autowired
    private ISkuAttrValuesService skuAttrValuesService;

    /**
     * 查询sku属性值表列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuesvalues:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkuAttrValues skuAttrValues)
    {
        startPage();
        List<SkuAttrValues> list = skuAttrValuesService.selectSkuAttrValuesList(skuAttrValues);
        return getDataTable(list);
    }


    /**
     * 导出sku属性值表列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuesvalues:export')")
    @Log(title = "sku属性值表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuAttrValues skuAttrValues)
    {
        List<SkuAttrValues> list = skuAttrValuesService.list();
        ExcelUtil<SkuAttrValues> util = new ExcelUtil<SkuAttrValues>(SkuAttrValues.class);
        util.exportExcel(response, list, "sku属性值表数据");
    }

    /**
     * 获取sku属性值表详细信息
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuesvalues:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(skuAttrValuesService.getById(id));
    }

    /**
     * 新增sku属性值表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuesvalues:add')")
    @Log(title = "sku属性值表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkuAttrValues skuAttrValues)
    {
        return toAjax(skuAttrValuesService.save(skuAttrValues));
    }

    /**
     * 修改sku属性值表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuesvalues:edit')")
    @Log(title = "sku属性值表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkuAttrValues skuAttrValues)
    {
        return toAjax(skuAttrValuesService.updateById(skuAttrValues));
    }

    /**
     * 删除sku属性值表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuesvalues:remove')")
    @Log(title = "sku属性值表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Integer> ids)
    {
        return toAjax(skuAttrValuesService.removeByIds(ids));
    }
}